$(document).ready(function() {
	$("#scheduler").kendoScheduler({
		date : new Date("2013/6/6"),
		showWorkHours : true,
		height : 500,
		views : [ {
			type : "day",
			title : "D"
		}, {
			type : "week",
			title : "W"
		}, {
			type : "month",
			title : "M"
		} ],
		dataSource : [ {
			id : 1,
			start : new Date("2013/6/6 08:00 AM"),
			end : new Date("2013/6/6 09:00 AM"),
			title : "Interview"
		} ]
	});

});

function drawRotationChart() {
	var chData = "";
	var chartId = "dashBoardChart";
	var order = [ 0, 1, 2 ], i = 0, rotateTimer, t = 5000;
	$
			.getJSON(
					'resources/app/js/chartData1.json',
					function(result) {
						chData = result.da;

						if (chData && chData.length > 0) {
							updateChart(0);
							rotateTimer = setTimeout(rotateChart, t);
						} else {
							$("#" + chartId)
									.html(
											"<div Style='min-height: inherit;line-height:170px;text-align:center;'>Configure charts on dashboard using <i class='fa fa-cog'></i></div>");

						}
					}).error(function(xhr, ajaxOptions, thrownError) {
				alert(thrownError);
			});

	function rotateChart() {
		i += 1;
		i = (i >= order.length) ? 0 : i;
		updateChart(order[i]);
		rotateTimer = setTimeout(rotateChart, t);
	}
	$("#btnStopTimer").click(function() {
		if (rotateTimer) {
			clearTimeout(rotateTimer);
			rotateTimer = null;
			$(this).find("i").removeClass("fa-pause");
			$(this).find("i").addClass("fa-play");
		} else {
			rotateTimer = setTimeout(rotateChart, 1000);
			$(this).find("i").removeClass("fa-play");
			$(this).find("i").addClass("fa-pause");
		}
	});

	$("#btnPrevChart").click(function() {

		i -= 1;
		i = (i <= -1) ? order.length - 1 : i;
		updateChart(order[i]);
	});
	$("#btnNextChart").click(function() {
		i += 1;
		i = (i >= order.length) ? 0 : i;
		updateChart(order[i]);
	});

	function updateChart(i) {
		var chartConfig = chData[i].configuration;

		chartConfig.dataSource = {
			data : chData[i].chartData
		};

		$("#" + chartId).kendoChart(chartConfig);
		$(".title[for='" + chartId + "']").html(chartConfig.title.text);
	}
}
$(document).ready(function() {
	drawRotationChart();
	updateProgress();

});

function updateProgress() {
	$("[data-percent]").each(function() {
		return $(this).css({
			width : "" + ($(this).attr("data-percent")) + "%"
		});
	});
}